<template>
  <el-card :body-style="{ padding: '0px' }" shadow="always">
    <div class="mall-card-img">
      <div class="storey" v-if="props.data.off">
        <div class="storey-title">已下架</div>
      </div>
      <img :src="props.data.src" class="image" />
    </div>

    <div style="padding: 14px">
      <div class="mall-header">
        <span>商品名称： {{ props.data.name }}</span>
        <el-icon class="mall-header-icon" size="20" @click="handleClick"
          ><Setting
        /></el-icon>
      </div>

      <div class="bottom">
        <div class="mall-card-price price" v-if="!props.data.discount">
          <div>价格：{{ props.data.price }}</div>
        </div>
        <div class="mall-card-price" v-else>
          <p>折扣价：{{ props.data.discount }}</p>
          <div>
            原价：
            <span class="discount-text">{{ props.data.price }}</span>
          </div>
        </div>
        <el-switch
          v-model="props.data.off"
          class="button"
          active-text="下架"
          inactive-text="上架"
          @change="handleChange(props.data.off, props.data.id)"
        />
      </div>
    </div>
  </el-card>
</template>

<script setup>
const props = defineProps({
  data: {
    type: Object,
    default: () => {
      return {};
    },
  },
});
//注册事件
const emit = defineEmits(["SetOff", "setMall"]);

//点击商品上下架
const handleChange = (val, id) => {
  emit("SetOff", { off: val, id });
};

//点击设置商品
const handleClick = () => {
  emit("setMall", props.data);
};
</script>

<style lang="less" scoped>
.mall-card-price {
  font-size: 12px;
  &.price {
    font-size: 15px;
  }
  div {
    margin-top: 5px;
  }
  .discount-text {
    color: #999;
    text-decoration: line-through;
  }
}

.mall-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  .mall-header-icon {
    &:hover {
      color: #67c23a;
    }
  }
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.button {
  padding: 0;
  min-height: auto;
}

.image {
  width: 100%;
  display: block;
}

.mall-card-img {
  position: relative;
  .storey {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 99;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    .storey-title {
      font-size: 2em;
      color: #ccc;
    }
  }
}
</style>
